//
//  WGQTransfersRecordsHeaderView.m
//  meiang_edu
//
//  Created by gq w on 2018/9/26.
//  Copyright © 2018年 com.meiang.meiang_edu. All rights reserved.
//  接送，考勤记录的顶部视图

#import "WGQTransfersRecordsHeaderView.h"

@interface WGQTransfersRecordsHeaderView ()

@property (nonatomic,strong) UIView * topView;
@property (nonatomic,strong) UIView * bottomView;

//top
@property (nonatomic,strong) UIImageView * iconImageView;
@property (nonatomic,strong) UILabel * nameLabel;
@property (nonatomic,strong) UILabel * subtitleLabel;

//bottom
@property (nonatomic,strong) UIButton * leftButton;
@property (nonatomic,strong) UIButton * rightButton;
@property (nonatomic,strong) UILabel * yearMonthLabel;

@end

@implementation WGQTransfersRecordsHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self addSubViews];
        self.backgroundColor = FFColor(0xEBEBEB);
    }
    return self;
}

- (void)addSubViews
{
    //top
    self.topView = [[UIView alloc] init];
    self.topView.backgroundColor = FFColor(0xffffff);
    self.topView.layer.masksToBounds = YES;
    self.topView.layer.cornerRadius = 7 * kScale;
    [self addSubview:self.topView];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make)
    {
        make.left.equalTo(self.mas_left);
        make.top.equalTo(self.mas_top).offset(4 * kScale);
        make.right.equalTo(self.mas_right);
        make.height.mas_equalTo(64 * kScale);
    }];
    
    self.iconImageView = [[UIImageView alloc] init];
    self.iconImageView.layer.masksToBounds = YES;
    self.iconImageView.layer.cornerRadius = 20 * kScale;
    [self.topView addSubview:self.iconImageView];
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make)
    {
        make.left.equalTo(self.topView.mas_left).offset(12 * kScale);
        make.top.equalTo(self.topView.mas_top).offset(12 * kScale);
        make.width.and.height.mas_equalTo(40 * kScale);
    }];
    
    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(iconClick)];
    [self.iconImageView addGestureRecognizer:tapGesture];
    self.iconImageView.userInteractionEnabled = YES;
    
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.textColor = FFColor(0x333333);
    self.nameLabel.font = [UIFont fontWithName:kMainFontFormat size:18 * kScale];
    self.nameLabel.textAlignment = NSTextAlignmentLeft;
    [self.topView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make)
    {
        make.left.equalTo(self.iconImageView.mas_right).offset(12 * kScale);
        make.top.equalTo(self.iconImageView.mas_top);
    }];
    
    self.subtitleLabel = [[UILabel alloc] init];
    self.subtitleLabel.textColor = FFColor(0x999999);
    self.subtitleLabel.font = [UIFont fontWithName:kMainFontFormat size:14 * kScale];
    self.subtitleLabel.textAlignment = NSTextAlignmentLeft;
    [self.topView addSubview:self.subtitleLabel];
    [self.subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make)
    {
        make.left.equalTo(self.nameLabel.mas_left);
        make.bottom.equalTo(self.iconImageView.mas_bottom);
    }];
    
    //bottom
    self.bottomView = [[UIView alloc] init];
    self.bottomView.backgroundColor = FFColor(0xffffff);
    self.bottomView.layer.masksToBounds = YES;
    self.bottomView.layer.cornerRadius = 7 * kScale;
    [self addSubview:self.bottomView];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make)
    {
        make.left.equalTo(self.topView.mas_left);
        make.right.equalTo(self.topView.mas_right);
        make.top.equalTo(self.topView.mas_bottom).offset(4 * kScale);
        make.height.mas_equalTo(40 * kScale);
    }];
        
    self.leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.leftButton setImage:[UIImage imageNamed:@"LeftArrow"] forState:UIControlStateNormal];
    [self.leftButton addTarget:self action:@selector(leftButtonActionWithSender:) forControlEvents:UIControlEventTouchUpInside];
    [self.bottomView addSubview:self.leftButton];
    [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make)
    {
        make.width.and.height.mas_equalTo(16 * kScale);
        make.left.and.top.equalTo(self.bottomView).offset(12 * kScale);
    }];
    
    self.rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.rightButton setImage:[UIImage imageNamed:@"RightArrow"] forState:UIControlStateNormal];
    [self.rightButton addTarget:self action:@selector(rightButtonActionWithSender:) forControlEvents:UIControlEventTouchUpInside];
    [self.bottomView addSubview:self.rightButton];
    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.width.and.height.mas_equalTo(16 * kScale);
         make.right.and.bottom.equalTo(self.bottomView).offset(-12 * kScale);
     }];
    
    self.yearMonthLabel = [[UILabel alloc] init];
    self.yearMonthLabel.textColor = FFColor(0x999999);
    self.yearMonthLabel.font = [UIFont fontWithName:kMainFontFormat size:14 * kScale];
    self.yearMonthLabel.textAlignment = NSTextAlignmentCenter;
    [self.bottomView addSubview:self.yearMonthLabel];
    [self.yearMonthLabel mas_makeConstraints:^(MASConstraintMaker *make)
    {
        make.top.and.bottom.equalTo(self.bottomView);
        make.left.equalTo(self.leftButton.mas_right);
        make.right.equalTo(self.rightButton.mas_left);
    }];
}

- (void)leftButtonActionWithSender:(UIButton *)sender
{
    if (self.is_left_click_block)
    {
        self.is_left_click_block(YES);
    }
}

- (void)rightButtonActionWithSender:(UIButton *)sender
{
    if (self.is_left_click_block)
    {
        self.is_left_click_block(NO);
    }
}

 - (void)changeBabyMessageWithModel:(WGQTransfersRecordsBabyModel *)model
{
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IMG_OSS,model.ps_id]]];
    self.nameLabel.text = model.cname;
    self.subtitleLabel.text = model.school_name;
}

- (void)changeTimeLabelTextWithYearStr:(NSString *)yearStr monthStr:(NSString *)monthStr
{
    self.yearMonthLabel.text = [NSString stringWithFormat:@"%@-%@",yearStr,monthStr];
}

- (void)iconClick
{
    if (self.is_click)
    {
        self.is_click(YES);
    }
}

- (void)setObject:(id)object
{
    
}

@end
